package com.borqs.music.http;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.zip.GZIPInputStream;

public class HttpResponseImpl extends HttpResponse {
    private HttpURLConnection con;
    HttpResponseImpl(HttpURLConnection con) throws IOException {
        this.con = con;
        this.statusCode = con.getResponseCode();
        if(null == (is = con.getErrorStream())){
            is = con.getInputStream();
        }
        
        if (null != is && "gzip".equals(con.getContentEncoding())) {
            // the response is gzipped
            is = new GZIPInputStream(is);
        }
    }

    // for test purpose
    /*package*/ HttpResponseImpl(String content) {
        this.responseAsString = content;
    }

    @Override
    public String getResponseHeader(String name) {
        return con.getHeaderField(name);
    }

    /**
     * {@inheritDoc}
     */
    public void disconnect(){
        con.disconnect();
    }
}
